home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / oploterr.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  110 lines

  1. ; $Id: oploterr.pro,v 1.4 1997/03/27 23:51:28 kirk Exp $
  2.  
  3. PRO OPLOTERR, X, Y, ERR, PSYM
  4. ;
  5. ;+
  6. ; NAME:
  7. ;    OPLOTERR
  8. ;
  9. ; PURPOSE:
  10. ;    Overplot data points with accompanying error bars.
  11. ;
  12. ; CATEGORY:
  13. ;    Plotting, 2-dimensional.
  14. ;
  15. ; CALLING SEQUENCE:
  16. ;    OPLOTERR, [ X ,]  Y , Err  [, Psym ]
  17. ;
  18. ; INPUTS:
  19. ;    Y:    The array of Y values.
  20. ;
  21. ;    Err:    The array of error bar values.
  22. ;
  23. ; OPTIONAL INPUT PARAMETERS:
  24. ;    X:    An optional array of X values.  The procedure checks whether 
  25. ;        or not the third parameter passed is a vector to decide if X 
  26. ;        was passed.
  27. ;        
  28. ;        If X is not passed, then INDGEN(Y) is assumed for the X values.
  29. ;
  30. ;    PSYM:    The plotting symbol to use (default = +7).
  31. ;
  32. ; COMMON BLOCKS:
  33. ;    None.
  34. ;
  35. ; SIDE EFFECTS:
  36. ;    None.
  37. ;
  38. ; RESTRICTIONS:
  39. ;    Arrays cannot be of type string.  There must be enough points to
  40. ;    plot.
  41. ;
  42. ; PROCEDURE:
  43. ;    A plot of X versus Y with error bars drawn from Y - ERR to Y + ERR
  44. ;    is written to the output device over any plot already there.
  45. ;
  46. ; MODIFICATION HISTORY:
  47. ;    William Thompson    Applied Research Corporation
  48. ;    July, 1986        8201 Corporate Drive
  49. ;                Landover, MD  20785
  50. ;       kdb, March, 1997  - Fixed a problem if 1 element arrays where used.
  51. ;-
  52. ;
  53. P_SYM = !P.PSYM        ; Save the affected system parameters
  54. LINESTYLE = !P.LINESTYLE
  55. ;
  56. ;  Interpret the input parameters.
  57. ;
  58. ON_ERROR,2              ; Return to caller if an error occurs
  59. NP = N_PARAMS(0)
  60. IF NP LT 2 THEN $
  61.   message, 'Must be called with 2-4 parameters: [ X ,]  Y , ERR  [, PSYM ]' $
  62.  ELSE IF NP EQ 2 THEN BEGIN            ;Only Y and ERR passed.
  63.     !P.PSYM = 7
  64.     YERR = Y
  65.     YY = X
  66.     XX = INDGEN(n_elements(x))
  67. END ELSE IF NP GE 3 THEN BEGIN
  68. ; If err is a scalar, x array was not passed.
  69.     IF((size(err))(0) EQ 0)THEN BEGIN  ;X array not passed.
  70.         !P.PSYM = ERR
  71.         YERR = Y
  72.         YY = X
  73.         XX = INDGEN(Y)
  74.     END ELSE BEGIN                ;X array passed.
  75.         IF NP EQ 3 THEN !P.PSYM = 7 $
  76.             ELSE !P.PSYM = PSYM
  77.         YERR = ERR
  78.         YY = Y
  79.         XX = X
  80.     END
  81. END
  82. ;
  83. ;  Plot data and the error bars.
  84. ;
  85. N = N_ELEMENTS(XX) < N_ELEMENTS(YY) < N_ELEMENTS(YERR)
  86. IF N LT 1 THEN message, 'No points to plot.' $
  87. ELSE IF N EQ 1 THEN BEGIN        ;Double XX and YY arrays to allow
  88.     XX = [XX[0],XX[0]]        ;    plotting of single point.
  89.     YY = [YY[0],YY[0]]
  90.     YERR = [YERR[0],YERR[0]]
  91. END ELSE BEGIN
  92.     XX = XX[0:N-1]
  93.     YY = YY[0:N-1]
  94. ENDELSE
  95. OPLOT,XX,YY                ;Plot data points.
  96. !P.PSYM = 0
  97. !P.LINESTYLE = 0
  98. FOR I = 0,N-1 DO BEGIN            ;Plot error bars.
  99.     XXX = [XX[I],XX[I]]
  100.     YYY = [YY[I]-YERR[I],YY[I]+YERR[I]]
  101.     OPLOT,XXX,YYY
  102. END
  103. ;
  104. !P.PSYM = P_SYM        ; Return the orginal system parameter values.
  105. !P.LINESTYLE = LINESTYLE
  106. ;
  107. RETURN
  108. END
  109.  
  110.